from manim import *



class math1(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(60*2+1):       
            dot1=Dot([-500,5*(i-60),0]).set_opacity(0.5)
            dot2=Dot([500,5*(i-60),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(100*2+1):        
            dot3=Dot([(i-100)*5,-300,0]).set_opacity(0.5)
            dot4=Dot([(i-100)*5,300,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])
        #镜头跟进效果 
        self.camera.frame.save_state()
        #题目出现
        self.play(self.camera.frame.animate.scale(1).move_to([0,0,0]))
        #题目出现
        text = Tex(r"\text{(张1000)设}$f\left( x\right) $\text{在}$[  0,+\infty ) $\text{上连续且有水平渐近线}$y=b\neq 0$\text{则}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,25,0])
        text1 = Tex(r"\text{(A)当}$a >0$\text{时,}$y'+ay=f\left( x\right) $\text{的任意解都满足}$\lim\limits _{x\rightarrow +\infty }y\left( x\right) =\dfrac{b}{a}$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-5,17,0])
        text2 = Tex(r"\text{(B)当}$a >0$\text{时,}$y'+ay=f\left( x\right) $\text{的任意解都满足}$\lim\limits _{x\rightarrow +\infty }y\left( x\right) =\dfrac{a}{b}$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-5,9,0])
        text3 = Tex(r"\text{(C)当}$a <0$\text{时,}$y'+ay=f\left( x\right) $\text{的任意解都满足}$\lim\limits _{x\rightarrow +\infty }y\left( x\right) =\dfrac{b}{a}$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-5,1,0])
        text4 = Tex(r"\text{(D)当}$a <0$\text{时,}$y'+ay=f\left( x\right) $\text{的任意解都满足}$\lim\limits _{x\rightarrow +\infty }y\left( x\right) =\dfrac{a}{b}$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-5,-7,0])
        

        

        self.play(Create(text),Create(text1),Create(text2),Create(text3),Create(text4))
        
        #镜头拉回
          #分析文本
        #text100=MarkupText("<b><i>分析/解：</i></b>",color=PINK).scale(5.0).move_to([-38,12.5,0])
        self.play(FadeIn(dot1),run_time=0.1)
        self.play(FadeIn(dot2),run_time=0.1)
        self.play(FadeIn(dot3),run_time=0.1)

        #题目向上移动
        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=20,height=30
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([-15, 5, 0])
        self.play(Create(rectangle))
        text5 = Tex(r"$y=e^{-ax}\left[ \int f\left( x\right) e^{ax}dx+c\right] $",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-30,-17,0])
        text6 = Tex(r"$y=e^{-ax}\left[ \int _{0}^{x}f\left( t\right) e^{at}dt+c\right] $",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-30,-17,0])
        self.play(
           
            ReplacementTransform(rectangle,text5)
        )
        self.wait(0.2)
         #题目向上移动
        rectangle1=Rectangle(color=BLUE,fill_opacity=0.0,width=15,height=30
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle1.move_to([22.5, 5, 0])
        self.play(Create(rectangle1))
        self.play(
            ReplacementTransform(text5,text6)
            ,ReplacementTransform(rectangle1,text6)
        )
        self.wait(0.2)
        arrow = Arrow(start=[-13,-17,0],end=[-5,-17,0],color=RED
                       , stroke_width=20, tip_length=1)

        self.play(GrowArrow(arrow))
        text7 = Tex(r"$\lim\limits _{x\rightarrow +\infty } y=e^{-ax}\left[ \int _{0}^{x}f\left( t\right) e^{at}dt+c\right] $",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([15,-17,0])
        self.play(Create(text7))
        text8 = Tex(r"$\lim\limits _{x\rightarrow +\infty }\dfrac{\int _{0}^{x}f\left( t\right) e^{at}dt+c}{e^{ax}}$",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([10,-17,0])
        self.play(
            ReplacementTransform(text7,text8)
            
        )
        self.wait(0.2)
        #题目向上移动
        rectangle20=Rectangle(color=BLUE,fill_opacity=0.0,width=10,height=15
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle20.move_to([-30, 13, 0])
        self.play(Create(rectangle20))
        text9 = Tex(r"$\infty $",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(8.0).move_to([15,-22,0])
        self.play(Create(text9))
        text10 = Tex(r"$==\lim\limits _{x\rightarrow +\infty }\dfrac{f\left( x\right) \cdot e^{ax}}{ae^{ax}}$",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text8,RIGHT,buff=1)
        text11 = Tex(r"\text{洛}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(8.0).move_to([26,-15,0])
        self.play(Create(text11),Create(text10),FadeOut(text9))
        text12 = Tex(r"$\left( \dfrac{0}{0}\right) ,\left( \dfrac{\infty }{\infty }\right) ,\left( \dfrac{?}{\infty }\right) $",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(8.0).move_to([0,-25,0])
        self.play(Create(text12),run_time=2)
        self.play(FadeOut(text12))
         #题目向上移动
        rectangle2=Rectangle(color=BLUE,fill_opacity=0.0,width=20,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle2.move_to([20, 25, 0])
        self.play(Create(rectangle2))

        text13 = Tex(r"$\lim\limits _{x\rightarrow +\infty }f\left( x\right) =b$",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([40,10,0])
        self.play(
            ReplacementTransform(rectangle2,text13)
            
        )
        self.wait(0.2)
        self.play(self.camera.frame.animate.scale(1.2).move_to([5,-5,0]))
        text14 = Tex(r"$=\dfrac{b}{a} $",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text10,RIGHT,buff=1)
        self.play(
            ReplacementTransform(text13,text14)
            
        )
        self.wait(0.2)
        rectangle4=Rectangle(color=BLUE,fill_opacity=0.5,width=1,height=2.8
                            ,stroke_color=YELLOW,stroke_width=0).move_to([-5,17,0])
        self.play(
            rectangle4.animate.stretch(70.0,dim=0)
        )

        #题目向上移动
        rectangle3=Rectangle(color=BLUE,fill_opacity=0.0,width=10,height=15
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle3.move_to([-30, -2, 0])
        self.play(
            ReplacementTransform(rectangle20,rectangle3),
            FadeOut(text10),
            FadeOut(text14),
            FadeOut(text11)
        )
        self.wait(0.2)
        self.camera.frame.save_state()
        self.play(self.camera.frame.animate.scale(0.7).move_to([13,-20,0]))
        text9 = Tex(r"$0$",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(8.0).move_to([15,-22,0])
        self.play(Create(text9))
        rectangle5=Rectangle(color=PURE_GREEN,fill_opacity=0.5,width=1,height=2.8
                            ,stroke_color=YELLOW,stroke_width=0).move_to([12.5,-15,0])
        self.play(
            rectangle5.animate.stretch(15.0,dim=0)
        )
        text10 = Tex(r"$\int _{0}^{+\infty }f\left( x\right) e^{ax}dx$",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-45,-30,0])
        self.play(
            ReplacementTransform(rectangle5,text10)
            ,Restore(self.camera.frame)
        )
        self.wait(0.2)
        arrow = Arrow(start=[-33,-30,0],end=[-25,-30,0],color=RED
                       , stroke_width=20, tip_length=1)

        self.play(GrowArrow(arrow))
        text11 = Tex(r"$f\left( x\right) e^{ax}$",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-15,-30,0])
        self.play(Create(text11))
        text12 = Tex(r"\text{等价于}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text11,RIGHT,buff=3)
        self.play(Create(text12))
        text13 = Tex(r"$be^{ax}$",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text12,RIGHT,buff=3)
        self.play(Create(text13))
        text14 = Tex(r"\text{与}$e^{ax}$\text{同敛散}",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text13,RIGHT,buff=3)
        self.play(Create(text14))
        text15 = Tex(r"\text{与}$\dfrac{1}{e^{-ax}}$\text{同敛散}",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text13,RIGHT,buff=3)
        self.play(
            ReplacementTransform(text14,text15)
            
        )   
        self.wait(0.2)
        text16 = Tex(r"$e^{-ax}\gg x^{2}$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(7.0).next_to(text15,DOWN,buff=3)
        self.play(Create(text16))
        text17 = Tex(r"$\dfrac{1}{e^{-ax}} <\dfrac{1}{x^{2}}$",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text15,RIGHT,buff=3)
        self.play(
            ReplacementTransform(text16,text17)
            
        )
        self.wait(0.2)
        text18 = Tex(r"$\int _{1}^{+\infty }\dfrac{1}{x^{2}}dx$\text{收敛}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text17,RIGHT,buff=3)
        rectangle2=Rectangle(color=BLUE,fill_opacity=0.0,width=15,height=7
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle2.next_to(text17,RIGHT,buff=3)
        self.play(Create(text18),Create(rectangle2))
        self.wait(0.2)
        #框框移动
        self.play(rectangle2.animate().next_to(text13,RIGHT,buff=3))
        self.play(rectangle2.animate().stretch(1.2,dim=0).move_to([-45,-30,0]))
        text19 = Tex(r"$d$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(7.0).next_to(text10,UP,buff=3)
        self.play(Create(text19))
        text20 = Tex(r"\text{当}$d+c=0$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(7.0).move_to([45,10,0])
        self.play(Create(text20))
        text201 = Tex(r"$0$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(7.0).move_to([20,-13,0])
        self.play(Create(text201))
        text10 = Tex(r"$==\lim\limits _{x\rightarrow +\infty }\dfrac{f\left( x\right) \cdot e^{ax}}{ae^{ax}}=\dfrac{b}{a} $",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text8,RIGHT,buff=1)
        text11 = Tex(r"\text{洛}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(8.0).move_to([26,-15,0])
        self.play(Create(text11),Create(text10))
        text21 = Tex(r"\text{当}$d+c\neq 0$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(7.0).next_to(text20,DOWN,buff=3)
        self.play(Create(text21),FadeOut(text201),FadeOut(text10),FadeOut(text11))
        text22 = Tex(r"$=\infty $",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(7.0).next_to(text8,RIGHT,buff=2)
        self.play(Create(text22))
        self.wait()





